<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .grandmother{
            background-color: pink;
            width: 500px;
            height: 500px;
        }
        .mother{
            background-color: yellow;
            width: 400px;
            height: 400px;

        }
        .daughter{
            background-color: aquamarine;
            width: 300px;
            height: 300px;

        }
        .baby{
            background-color: blue;
            width: 200px;
            height: 200px;

        }
    </style>
</head>
<body>
    <div class="grandmother" style="color:blueviolet;">grandmother 奶奶
        <div class="mother">mother 妈妈
          <div class="daughter">daughter 女儿
            <div class="baby">baby 婴儿</div>
          </div>
        </div>
    </div>
    <script>
        let grandmother=document.getElementsByClassName("grandmother")[0]
        let mother=document.getElementsByClassName("mother")[0]
        let daughter=document.getElementsByClassName("daughter")[0]
        let baby=document.getElementsByClassName("baby")[0]
        function theName(){
            console.log("我是"+this.className)
        }
        //捕获的优先级比冒泡的高
        baby.addEventListener("click",theName,false)//冒泡
        daughter.addEventListener("click",theName,true)//捕获
        mother.addEventListener("click",theName,true)//捕获
        grandmother.onclick=theName//冒泡
    </script>
</body>
</html>